package com.anysoft.greenDAO.db;

import android.content.Context;
import android.util.Log;

import com.anysoft.greenDAO.dao.DaoMaster;
import com.anysoft.greenDAO.dao.PwdBeanDao;
import com.anysoft.greenDAO.dao.UserBeanDao;

import org.greenrobot.greendao.database.Database;

/**
 * Created by wwq on 2016/11/16.
 */

public class MyOpenHelper extends DaoMaster.OpenHelper {
    public MyOpenHelper(Context context, String name) {
        super(context, name);
    }


    //有数据库更新时，一定要在此处删除之前的数据库
    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        Log.i(getClass().getSimpleName(), "db version update from " + oldVersion + " to " + newVersion);

        switch (oldVersion) {
            case 1:
                PwdBeanDao.createTable(db, true);

                // 加入新字段 score
                db.execSQL("ALTER TABLE 't_userInfo' ADD 'sex' TEXT;");
                db.execSQL("ALTER TABLE 't_userInfo' ADD 'RECORD_IDENT_NUMBER' TEXT;");
                db.execSQL("ALTER TABLE 't_userInfo' ADD 'LAST_LOGIN_TIME' INTEGER;");
//                db.execSQL("update t_userInfo set RECORD_IDENT_NUMBER='1';");
                db.execSQL("delete from  t_userInfo;");
                //删除字段
                //alter table 'tablename' drop column 'name'
                break;

        }
        MigrationHelper.getInstance().migrate(db, UserBeanDao.class,PwdBeanDao.class);
    }
}